home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 February / PCWFEB09.iso / Software / Linux / SLAX 6.0.8 / slax-6.0.8.iso / slax / base / 006-devel.lzm / usr / include / kunittest / module.h next >
Encoding:
C/C++ Source or Header  |  2006-01-19  |  7.5 KB  |  121 lines

  1. /*
  2.  * Copyright (C)  2005  Jeroen Wijnhout <Jeroen.Wijnhout@kdemail.net>
  3.  *
  4.  * Redistribution and use in source and binary forms, with or without
  5.  * modification, are permitted provided that the following conditions
  6.  * are met:
  7.  *
  8.  * 1. Redistributions of source code must retain the above copyright
  9.  *   notice, this list of conditions and the following disclaimer.
  10.  * 2. Redistributions in binary form must reproduce the above copyright
  11.  *   notice, this list of conditions and the following disclaimer in the
  12.  *   documentation and/or other materials provided with the distribution.
  13.  *
  14.  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
  15.  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  16.  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  17.  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
  18.  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  19.  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  20.  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  21.  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  22.  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  23.  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  24.  */
  25.  
  26. /*!
  27.  * @file module.h
  28.  * Provides macros to ease building unit tests as shared libraries
  29.  */
  30.  
  31. #ifndef KUNITTEST_MODULE_H
  32. #define KUNITTEST_MODULE_H
  33.  
  34. #include <qstring.h>
  35.  
  36. #include <klibloader.h>
  37. #include <kunittest/runner.h>
  38.  
  39. namespace KUnitTest
  40. {
  41.     /*! @def KUNITTEST_MODULE(library,suite)
  42.     * Use this macro if you are creating a KUnitTest module named library. 
  43.     * This macro creates a module-class named a factory class. The module
  44.     * will appear under the name suite in the test runner.
  45.     * There is no need in calling the K_EXPORT_COMPONENT_FACTORY macro,
  46.     * this is taken care of automatically.
  47.     * 
  48.     * @code KUNITTEST_MODULE(kunittest_samplemodule,"TestSuite") @endcode
  49.     */
  50.     #define KUNITTEST_MODULE(library,suite)                                                 \
  51.     static const QString s_kunittest_suite  = QString::fromLatin1(suite);                   \
  52.     class library##Module : public QObject                                                  \
  53.     {                                                                                       \
  54.     public:                                                                                 \
  55.         library##Module()                                                                   \
  56.         {                                                                                   \
  57.             KUnitTest::RegistryIteratorType it(s_registry);                                 \
  58.             for( ; it.current(); ++it )                                                     \
  59.                 KUnitTest::Runner::registerTester(it.currentKey(), it.current());           \
  60.         }                                                                                   \
  61.                                                                                             \
  62.         static KUnitTest::RegistryType s_registry;                                          \
  63.     };                                                                                      \
  64.                                                                                             \
  65.     KUnitTest::RegistryType library##Module::s_registry;                                    \
  66.                                                                                             \
  67.     void kunittest_registerModuleTester(const char *name, KUnitTest::Tester *test)          \
  68.     {                                                                                       \
  69.         library##Module::s_registry.insert(name, test);                                     \
  70.     }                                                                                       \
  71.                                                                                             \
  72.     class module##Factory : public KLibFactory                                              \
  73.     {                                                                                       \
  74.     public:                                                                                 \
  75.         QObject *createObject (QObject *, const char *, const char *, const QStringList &)  \
  76.         {                                                                                   \
  77.             return new library##Module();                                                   \
  78.         };                                                                                  \
  79.     };                                                                                      \
  80.                                                                                             \
  81.     K_EXPORT_COMPONENT_FACTORY( library, module##Factory )
  82.  
  83.     /*! @def KUNITTEST_MODULE_REGISTER_TESTER(tester)
  84.     * Use this macro to add a tester class to your module. The name of the tester will
  85.     * be identical to the class name.
  86.     *
  87.     * @code KUNITTEST_MODULE_REGISTER_TESTER(SimpleSampleTester) @endcode
  88.     */
  89.     #define KUNITTEST_MODULE_REGISTER_TESTER( tester)                                           \
  90.     static class tester##ModuleAutoregister                                                     \
  91.     {                                                                                           \
  92.     public:                                                                                     \
  93.         tester##ModuleAutoregister()                                                            \
  94.         {                                                                                       \
  95.             KUnitTest::Tester *test = new tester();                                             \
  96.             QString name = s_kunittest_suite + QString::fromLatin1("::") + QString::fromLocal8Bit(#tester); \
  97.             test->setName(name.local8Bit());                                                    \
  98.             kunittest_registerModuleTester(name.local8Bit(), test );                            \
  99.         }                                                                                       \
  100.     } tester##ModuleAutoregisterInstance;
  101.  
  102.     /*! @def KUNITTEST_MODULE_REGISTER_NAMEDTESTER(name,tester)
  103.     * Use this macro to add a tester class, with specified name, to your module..
  104.     *
  105.     * @code KUNITTEST_MODULE_REGISTER_TESTER("SubSuite::PrettyName",SimpleSampleTester) @endcode
  106.     */
  107.     #define KUNITTEST_MODULE_REGISTER_NAMEDTESTER( name , tester)                             \
  108.     static class tester##ModuleAutoregister                                                   \
  109.     {                                                                                         \
  110.     public:                                                                                   \
  111.         tester##ModuleAutoregister()                                                          \
  112.         {                                                                                     \
  113.             QString fullName = s_kunittest_suite + QString("::") + QString::fromLocal8Bit(name); \
  114.             KUnitTest::Tester *test = new tester(fullName.local8Bit());                       \
  115.             kunittest_registerModuleTester(fullName.local8Bit(), test);                       \
  116.         }                                                                                     \
  117.     } tester##ModuleAutoregisterInstance;
  118. }
  119.  
  120. #endif
  121.